Variables
Variable setup
Variables hold variable data to be used in templates and pipelines. Create variable templates per environment.
📁 variables
📝 pipelines-variables.yml
📝 pipelines-variables-tst.yml
📝 pipelines-variables-uat.yml
📝 pipelines-variables-prd.yml
Variable file usage
There is a generic pipeline-variables.yml file. This file is used to define generic variables that are not bound to an environment. For example, a subscription name (if you're using a single subscription) or namings of the project, client etc.
Example:
variables:
clientName: 'nameOfTheClient'
businessUnitName: 'nameOfTheBusinessunit'
projectName: 'nameOfTheProject'
appName: 'nameOfTheApplication'
azureSubscription: '[name of the azure devops service connection]'
Environment variables
Next to the generic variables, there are aslo variables that are bount to an environment, like the environment name itself, resource namings etc.
Eample:
variables:
environment: 'tst'
appTier: 'S1'
You can also define resource Tiers in the specific environment files. This way you can provision apps on the Test environment with a different tier then the apps on production.
Variable file usage
Variable templates can be added to a piplene. Variables will overwrite previously defined values.
In the example below, the generic variables are included on line #5. In a stage, an environment variable file is included (line #23, #30, #37). This way, both generic and environment variables are available in a stage. The advantage of this setup is that it is possible to use the same release template for the deployments. Only the value of the variables will be different.
####################################################### ADD GLOBAL VARIABLES######################################################variables:- template: 'variables/pipeline-variables.yaml' ####################################################### SET STAGES######################################################stages:########################################################### BUILD APPLICATION#######################################################- stage: STAGE_BUILD displayName: 'Stage - Build Stage'########################################################### STAGE - RELEASE TO TEST#######################################################- stage: STAGE_RELEASE_TST variables: - template: 'variables/pipeline-variables-tst.yml'########################################################### STAGE - RELEASE TO UAT#######################################################- stage: STAGE_RELEASE_UAT variables: - template: 'variables/pipeline-variables-uat.yml'########################################################### STAGE - RELEASE TO PRD#######################################################- stage: STAGE_RELEASE_PRD variables: - template: 'variables/pipeline-variables-prd.yml'
Variable usage
Now the variable files have been setup correctly, we can now use the variables in the templates.
Example:
####################################################### SET STAGES######################################################stages:########################################################### STAGE - PROVISION TEST ENVIRONMENT#######################################################- stage: STAGE_PROVISION_TEST variables: - template: 'variables/pipeline-variables-tst.yml' jobs: - template: 'templates/template-infra.yaml' parameters: azureSubscription: '${{ variables.azureSubscription }}' environment: '${{ variables.environment }}' appName: '${{ variables.appName }}' appTier: '${{ variables.appTier }}'########################################################### STAGE - PROVISION TEST ENVIRONMENT#######################################################- stage: STAGE_PROVISION_UAT variables: - template: 'variables/pipeline-variables-uat.yml' jobs: - template: 'templates/template-infra.yaml' parameters: azureSubscription: '${{ variables.azureSubscription }}' environment: '${{ variables.environment }}' appName: '${{ variables.appName }}' appTier: '${{ variables.appTier }}'
In this example, we're referencing the same template for provisioning the environments. Based upon the value in the variables files, we can have different tiers created for resources in the environments. This example is the pipeline only where the variables are passed to a template. Using the actual values is described in the Templates page.